import '../helper/Helper.dart';
import '../model/skddl.dart';

import '../../helper/cacheHelper.dart';
import '../../helper/signHelper.dart';

import '../helper/dioHelper2.dart';

class SKDDL2 {
  int ID;
  String Title;
  String Content;
  String ZhaMen;
  String CaoZuo;
  String ZBYName;
  String CreateTime;
  String BMHQ;
  String BMQM;
  String BMTM;
  String BMUserID;
  bool BMIfOK;
  String DCHQ;
  String DCQM;
  String DCTM;
  String DCUserID;
  bool DCIfOK;
  String GCBHQ;
  String GCBQM;
  String GCBTM;
  String GCBUserID;
  bool GCBIfOK;
  String LDSH;
  String SHQM;
  String SHTM;
  String SHUserID;
  bool SHIfOK;
  String LDHQ;
  String LDQM;
  String LDTM;
  String LDUserID;
  bool LDIfOK;
  String HZBXName;
  String HuiZhi;
  String HZTM;
  String HZQM;
  String HZQMTM;
  String HZUserID;
  bool HZIfOK;
  String Remark;
  int State;
  String Record;

  SKDDL2(
      this.ID,
      this.Title,
      this.Content,
      this.ZhaMen,
      this.CaoZuo,
      this.ZBYName,
      this.CreateTime,
      this.BMHQ,
      this.BMQM,
      this.BMTM,
      this.BMUserID,
      this.BMIfOK,
      this.DCHQ,
      this.DCQM,
      this.DCTM,
      this.DCUserID,
      this.DCIfOK,
      this.GCBHQ,
      this.GCBQM,
      this.GCBTM,
      this.GCBUserID,
      this.GCBIfOK,
      this.LDSH,
      this.SHQM,
      this.SHTM,
      this.SHUserID,
      this.SHIfOK,
      this.LDHQ,
      this.LDQM,
      this.LDTM,
      this.LDUserID,
      this.LDIfOK,
      this.HZBXName,
      this.HuiZhi,
      this.HZTM,
      this.HZQM,
      this.HZQMTM,
      this.HZUserID,
      this.HZIfOK,
      this.Remark,
      this.State,
      this.Record);
  SKDDL2.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Title = json["Title"],
        Content = json["Content"],
        ZhaMen = json["ZhaMen"],
        CaoZuo = json["CaoZuo"],
        ZBYName = json["ZBYName"],
        CreateTime = json["CreateTime"],
        BMHQ = json["BMHQ"],
        BMQM = json["BMQM"],
        BMTM = json["BMTM"],
        BMUserID = json["BMUserID"],
        BMIfOK = json["BMIfOK"],
        DCHQ = json["DCHQ"],
        DCQM = json["DCQM"],
        DCTM = json["DCTM"],
        DCUserID = json["DCUserID"],
        DCIfOK = json["DCIfOK"],
        GCBHQ = json["GCBHQ"],
        GCBQM = json["GCBQM"],
        GCBTM = json["GCBTM"],
        GCBUserID = json["GCBUserID"],
        GCBIfOK = json["GCBIfOK"],
        LDSH = json["LDSH"],
        SHQM = json["SHQM"],
        SHTM = json["SHTM"],
        SHUserID = json["SHUserID"],
        SHIfOK = json["SHIfOK"],
        LDHQ = json["LDHQ"],
        LDQM = json["LDQM"],
        LDTM = json["LDTM"],
        LDUserID = json["LDUserID"],
        LDIfOK = json["LDIfOK"],
        HZBXName = json["HZBXName"],
        HuiZhi = json["HuiZhi"],
        HZTM = json["HZTM"],
        HZQM = json["HZQM"],
        HZQMTM = json["HZQMTM"],
        HZUserID = json["HZUserID"],
        HZIfOK = json["HZIfOK"],
        Remark = json["Remark"],
        State = json["State"],
        Record = json["Record"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Title': Title,
        'Content': Content,
        'ZhaMen': ZhaMen,
        'CaoZuo': CaoZuo,
        'ZBYName': ZBYName,
        'CreateTime': CreateTime,
        'BMHQ': BMHQ,
        'BMQM': BMQM,
        'BMTM': BMTM,
        'BMUserID': BMUserID,
        'BMIfOK': BMIfOK,
        'DCHQ': DCHQ,
        'DCQM': DCQM,
        'DCTM': DCTM,
        'DCUserID': DCUserID,
        'DCIfOK': DCIfOK,
        'GCBHQ': GCBHQ,
        'GCBQM': GCBQM,
        'GCBTM': GCBTM,
        'GCBUserID': GCBUserID,
        'GCBIfOK': GCBIfOK,
        'LDSH': LDSH,
        'SHQM': SHQM,
        'SHTM': SHTM,
        'SHUserID': SHUserID,
        'SHIfOK': SHIfOK,
        'LDHQ': LDHQ,
        'LDQM': LDQM,
        'LDTM': LDTM,
        'LDUserID': LDUserID,
        'LDIfOK': LDIfOK,
        'HZBXName': HZBXName,
        'HuiZhi': HuiZhi,
        'HZTM': HZTM,
        'HZQM': HZQM,
        'HZQMTM': HZQMTM,
        'HZUserID': HZUserID,
        'HZIfOK': HZIfOK,
        'Remark': Remark,
        'State': State,
        'Record': Record,
      };
  static Future<bool> Add(SKDDL2 x1) async {
    var response = await DioHelper.Post("/SKDDL2/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(SKDDL2 x1) async {
    var response = await DioHelper.Post("/SKDDL2/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<String> SendById(
      String title, String content, String userId) async {
    var u1 = CacheHelper.GetUser(userId);

    var phone = u1.Phone;

    //phone="18884230190";

    return SignHelper.SendMessage2(title, "水库调度令-" + content, phone);
  }

  static Future<bool> Delete(SKDDL2 x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/SKDDL2/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<SKDDL2?> Get(int ID) async {
    var response = await DioHelper.Get("/SKDDL2/GetByID?id=$ID", {});

    if (response.statusCode == 200) return new SKDDL2.fromJson(response.data);
    return null;
  }

  static Future<SKDDL2> GetFromOld(SKDDL s1) async {
    var s2 = new SKDDL2.fromJson(s1.toJson());
    //print(s2.toJson());
    s2.BMQM = await Helper.GetImageBase64(s2.BMQM);
    print(s2.BMQM);
    s2.DCQM = await Helper.GetImageBase64(s2.DCQM);
    s2.GCBQM = await Helper.GetImageBase64(s2.GCBQM);
    s2.LDQM = await Helper.GetImageBase64(s2.LDQM);
    // s2.SHQM=await Helper.GetImageBase64(s2.LDQM);
    s2.SHIfOK = true;
    s2.SHTM = s2.LDTM;
    s2.SHUserID = s2.LDUserID;
    s2.SHQM = s2.LDQM;
    s2.State = 7;

    s2.HZQM = await Helper.GetImageBase64(s2.HZQM);
    //print(s2.toJson());
    return s2;
  }

  static Future<List<SKDDL2>> GetList(
      int State, int pageIndex, int pageSize) async {
    var response = await DioHelper.Get(
        "/SKDDL2/GetList?state=$State&page=$pageIndex&pageSize=$pageSize", {});
    var list1 = <SKDDL2>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new SKDDL2.fromJson(x));
      }
    }
    return list1;
  }
}
